package cn.edu.ujn.shi.controller;

import cn.edu.ujn.shi.dao.LoginLog;
import cn.edu.ujn.shi.service.ILoginLogService;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: LC
 * @date 2024-05-31 08:42
 * @ClassName: LoginLogController
 */
@Controller
public class LoginLogController {

    @Autowired
    private ILoginLogService loginLogService;

    @RequestMapping("/loginLog")
    public String doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        List<LoginLog> logs = loginLogService.getLoginLog(username);

        request.setAttribute("logs", logs);
        return "loginLog";
//        request.getRequestDispatcher("/jsp/loginLog").forward(request, response);
    }

    @RequestMapping("deleteLoginLogServlet")
    public void deleteLoginLogServlet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String id = request.getParameter("id");
        loginLogService.delete(Integer.parseInt(id));
        response.sendRedirect("loginLog");
    }


}
